from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI

from langchain_core.messages import HumanMessage, SystemMessage
from langchain_core.output_parsers import StrOutputParser

llm = ChatOpenAI(
    openai_api_base="https://api.siliconflow.cn/v1/",
    openai_api_key="sk-pdfifkpjdlxvyvgkerbluaotktpznsmpbcvskjauotenxgvz",  # app_key
    model_name="Qwen/Qwen3-8B",  # 模型名称
)

messages = [
    SystemMessage(content="你是一名优秀的AI助手，名字叫小白"),
    HumanMessage(content="你好，你是谁")

]
result = llm.invoke(messages)
print(result)



# llm = ChatOpenAI()
prompt = ChatPromptTemplate.from_messages([
    # SystemMessage(content="你是一名优秀的AI助手，名字叫小白"),
    ("system", "你是一名优秀的AI助手，名字叫小白"),
    ("human","{input}")
])

strOutputParser = StrOutputParser()
chain = prompt | llm | strOutputParser
result =  chain.invoke({"input":"你好，你是谁"})
print(result)
